package com.leo.javase.thread.itcast;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

public class CollectionModifyExceptionTest {

	public static void main(String[] args) {
		ArrayList<User> users = new ArrayList<User>();
				
				//ArrayList<User>(); CopyOnWriteArrayList<User>()
				
		users.add(new User("张三",28));
		users.add(new User("李四",24));
		users.add(new User("王五",26));
		
		Iterator<User> it = users.iterator();
		User user = null;
		while(it.hasNext()){
			user = it.next();
			if("张三".equals(user.getName())){
				//users.remove(user);
				it.remove();
			}else{
				System.out.println(user);
			}
		}
		/*for (int i = 0; i < users.size(); i++) {
			user = users.get(i);
			if("张三".equals(user.getName())){
				users.remove(user);
			}else{
				System.out.println(user);
			}
		}*/
		
		
	}

}
